package com.yuexunit.mobilenurse.module.BloodManage.presenter.impl;

import com.yuexunit.mobilenurse.module.BloodManage.bean.BloodBagDataBean;
import com.yuexunit.mobilenurse.module.BloodManage.model.IBloodBagApplyModel;
import com.yuexunit.mobilenurse.module.BloodManage.presenter.IBloodBagApplyPresenter;
import com.yuexunit.mobilenurse.module.BloodManage.ui.Act_Blood_ApplyDetail;
import com.yuexunit.mobilenurse.module.BloodManage.ui.view.IBloodBagApplyView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by work-jx on 2017/10/24.
 */
public class BloodBagApplyPresenter implements IBloodBagApplyPresenter {
    private IBloodBagApplyView view;
    private IBloodBagApplyModel model;

    public BloodBagApplyPresenter(IBloodBagApplyModel model, IBloodBagApplyView view) {
        this.model = model;
        this.view = view;
    }


    @Override
    public void getBloodBagDataList(Map<String, String> praise) {
        model.getBloodBagDataList(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BloodBagDataBean>() {
                               @Override
                               public void onCompleted() {

                               }

                               @Override
                               public void onError(Throwable e) {
                                   ViewInject.toast("获取血袋列表失败");
                                   view.PullDownRefreshState(Act_Blood_ApplyDetail.DOWNLOAD_NETERROR);
                               }

                               @Override
                               public void onNext(BloodBagDataBean bloodBagDataBean) {
                                   view.showBloodBagDataList(bloodBagDataBean);
                               }
                           }
                );
    }
}
